using System;
using LambdaGp.Core;

namespace LambdaGp.Operators.Functions.MathFunctions
{
    public class Sqrt : UnaryFunction
    {
        public Sqrt()
            : base("sqrt")
        {
        }

        protected override Func<double> CompileUnaryToFunc(Individual individual, Func<double> argument)
        {
            return () =>
            {
                double val = argument();
                if (val > 0)
                {
                    return Math.Sqrt(val);
                }
                else
                {
                    return 0;
                }
            };
        }
    }
}